<?php

namespace app\admin\controller\wechat;
use app\admin\controller\Base;
use think\facade\Request;
use think\facade\View;
use think\facade\Db;
use app\common\model\Wechat as WechatModel;
use helper\Wechat as WechatClass;
use EasyWeChat\Factory;

class Wxfans extends Base
{
	public function initialize()
    {
        parent::initialize(); 
        $map[] = ['status','=',1];
        $wx = WechatModel::where($map)->find();
        $this->Wechat = new WechatClass($wx['domain']);
        $this->app = Factory::officialAccount($this->Wechat->get_config());
        
        $this->wechatConfig = WechatModel::loadList([],100);
        View::assign('wechat',$this->wechatConfig['list']);
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
    	if (Request::isPost()) {
    	    $wechat_id = $this->request->post('wechat_id');

            $wx = WechatModel::where('id',$wechat_id)->find();
            $this->Wechat = new WechatClass($wx['domain']);
            $this->app = Factory::officialAccount($this->Wechat->get_config());

    		$userList = $this->app->user->list($nextOpenId = null);
        
	        $openid = [];
	        foreach ($userList['data']['openid'] as $key => $value){
	        	$openid[] = $value;
	        }
	        
	        $userInfo = $this->app->user->select($openid);
	        
	        return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $userInfo['user_info_list'], 'count' => $userList['total']];
    		
    	}
        return view();
        
    }
}
